﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.DynamicData;
using NotAClue.ComponentModel.DataAnnotations;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NotAClue.Web.DynamicData
{
    public static class AdvancedMetaModelExtensionMethods
    {
        /// <summary>
        /// Determines whether [is advanced column read only] [the specified column].
        /// </summary>
        /// <param name="column">The column.</param>
        /// <returns>
        /// 	<c>true</c> if [is advanced column read only] [the specified column]; otherwise, <c>false</c>.
        /// </returns>
        public static Boolean IsAdvancedColumnReadOnly(this MetaColumn column)
        {
            var pageTemplate = FieldTemplateExtensionMethods.GetPageTemplate();
            var columnReadOnlyIn = column.GetAttributeOrDefault<ColumnReadOnlyInAttribute>();

            if ((pageTemplate & columnReadOnlyIn.PageTemplate) == pageTemplate)
                return true;
            else
                return false;
        }
    }
}
